/**
 * @description 将对象转url参数
 * @param { Object } query
 */
export const useQueryToString = (query = {}) => {
    let q = "";
    for (const key in query) {
        q += q ? `&${key}=${query[key]}` : `?${key}=${query[key]}`
    }
    return q;
}


/**
 * @description 回车事件
 */

export const useEnterEvent = (event) => {
    function handleEnterEvent(e) {
        if (e.key === "Enter") {
            event()
            e.preventDefault();
        }
    }

    onBeforeMount(() => document.addEventListener('keydown', handleEnterEvent))
    onUnmounted(() => document.removeEventListener('keydown', handleEnterEvent))
}


/**
 * @description 时间事件
 * */

export const useTimeStatus = (start, end) => {
    start = new Date(start).getTime();
    end = new Date(end).getTime();
    const now = new Date().getTime();

    let status = '';
    if (start < now && end > now) {
        status = 'ing'
    } else if (start >= now) {
        status = 'pending'
    } else {
        status = 'end'
    }

    return status;
}
